package com.example.zhuzhuxia.schoolbus.Utils;

import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;

import java.io.IOException;

/**
 * Created by zhuzhuxia on 16/8/5.
 */
public class OkHttpUtils {
    public static String post(RequestBody body, String url) throws IOException{
        OkHttpClient client = new OkHttpClient();
        Request request=new Request.Builder()
                .url(url)
                .post(body)
                .build();

        Response response = client.newCall(request).execute();

        if (response.isSuccessful()) {
            return response.body().string();
        }
        else {
            throw new IOException("Unexpected code " + response);
        }
    }
}
